package cn.wo.action;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.wo.beans.Project;
import cn.wo.beans.Workorder;
import cn.wo.service.IProjectService;

public class ProjectAction extends ActionSupport implements ModelDriven<Workorder>{
	
	private IProjectService pservice;
	private Workorder order;
	
	public String optionlist(){
		List<Project> list = pservice.findAll();
		ActionContext.getContext().put("proList",list);
		return "option";
	}
	
	public String addOrder(){
		HttpServletRequest request = ServletActionContext.getRequest();
		Project project = pservice.getProjectByPid(Integer.parseInt(request.getParameter("pid")));
		Workorder workorder = new Workorder(project,request.getParameter("executor"),request.getParameter("description"),Integer.parseInt(request.getParameter("orderLevel")),new Date());
		System.out.println(workorder);
		pservice.addOrder(workorder);
		return "addok";
	}
	
	public String orderList(){
		List<Workorder> orderList = pservice.findAllOrder();
		ActionContext.getContext().put("orderList",orderList);
		return "orderlist";
	}
	
	
	
	
	
	
	
	
	
	
	
	public IProjectService getPservice() {
		return pservice;
	}

	public void setPservice(IProjectService pservice) {
		this.pservice = pservice;
	}

	public Workorder getModel() {
		return order;
	}
	public void setOrder(Workorder order) {
		this.order = order;
	}


	
	
	
	
	
	
}
